const { ListNode, LinkedList } = require('../2. 链表/1. 链表基础/1. 建立线性链表.js')
// 给定一个链表的头节点head，要求判断该链表是否为回文链表
// 思路，双指针
function isPalindrome(head) {
    let nodes = []
    let cur = head
    while (cur) {
        nodes.push(cur.val)
        cur =cur.next
    }
    let left = 0
    let right = nodes.length - 1
    while (left < right) {
        if (nodes[left] !== nodes[right]) {
            return false
        }
        left++
        right--
        
    }
    return true
}

let head = [1,2,2,1]
let node = new LinkedList(head)
console.log(isPalindrome(node.head))